package cn.jxufe.controller;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.jxufe.bean.EasyUIData;
import cn.jxufe.bean.EasyUIDataPageRequest;
import cn.jxufe.bean.Message;
import cn.jxufe.entity.Seed;
import cn.jxufe.service.SeedService;

/***
 * 种子管理
 * @author Banner
 *
 */
@Controller
@RequestMapping("seed")
public class SeedController {
	@Autowired
    private SeedService seedService;
	
	/***
	 * 页面跳转到seed/grid.jsp.
	 * @param session 请求
	 * @param model model
	 * @return String
	 */
	@RequestMapping("grid")
	public String grid(HttpSession session, Model model) {
		// 设置当前页面
		session.setAttribute("curPage", "seedGridPage");
		return "seed/grid";
	}
	
	/***
	 * 获取所有的种子信息.
	 * @return 种子信息列表
	 */
	@RequestMapping("list")
	@ResponseBody
	public List<Seed> list() {
		return seedService.list();
	}
	
	/***
	 * 以排序的形式获取所有种子的信息.
	 * @param seedName 种子名称
	 * @param easyUIDataPageRequest easyUI格式的数据，包含分页信息
	 * @param model model
	 * @return easyUI形式的种子信息列表
	 */
	@RequestMapping("getList")
	@ResponseBody
	public EasyUIData<Seed> getList(@RequestParam(defaultValue = "doNothing") String seedName, EasyUIDataPageRequest easyUIDataPageRequest, Model model) {
		System.out.println("seedName = " + seedName);
		EasyUIData<Seed> easyUIData = seedService.getList(seedName, easyUIDataPageRequest);
		System.out.println("这里的值为 = " + easyUIData.getTotal());
		return easyUIData;
	}
	
	/***
	 * 保存或修改种子信息.
	 * @param seed 种子对象
	 * @return Message
	 */
	@RequestMapping("save")
	@ResponseBody
	public Message save(Seed seed) {
		System.out.println("Seed value = " + seed.getSeedId());
		return seedService.save(seed);
	}
	
	/***
	 * 删除种子信息.
	 * @param seed 种子信息
	 * @return Message
	 */
	@RequestMapping("delete")
	@ResponseBody
	public Message delete(Seed seed) {
		System.out.println("正在删除数据！！！");
		return seedService.delete(seed);
	}
	
	
}
